{% extends 'cms/cms_base.html' %}

{% block title %}用例计划{% endblock %}

{% block head %}
    <script src="{{ static("cms/js/casePlanManage.js") }}"></script>
{% endblock %}

{% block page_title %}用例计划（共 {{ total }} 条数据）{% endblock %}

{% block main_content %}
    <div class="top-box-plan" style="float: right; padding-bottom: 5px;">
        <button class="btn btn-warning" data-toggle="modal" data-target="#addcaseplan-dialog">添加计划</button>
        <button type="button" class="btn btn-warning" id="refresh-btn" onclick="window.location.reload();">刷新</button>
    </div>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>计划名称</th>
                <th>执行方式</th>
                <th>关联组名称</th>
                <th>
                    <span data-toggle="tooltip" title="总用例数/可执行用例数">用例数<span class="glyphicon glyphicon-info-sign"></span></span>
                </th>
                <th>执行状态</th>
                <th>创建人</th>
                <th>更新人</th>
{#                <th style="width: 160px;">创建时间</th>#}
{#                <th style="width: 160px;">更新时间</th>#}
                <th style="width: 140px;">操作</th>
            </tr>
        </thead>
        <tbody>
            {% for plan in plans %}
                <tr data-plan_name="{{ plan.plan_name }}" data-case_run_way="{{ plan.case_run_way }}" data-case_count="{{ tem_groups[plan.plan_group][2] }}" data-gp_status="{{ tem_groups[plan.plan_group][3] }}" data-case_run_way_01="{{ plan.case_run_way_01 }}" data-delay_time="{{ plan.delay_time }}" data-group="{{ tem_groups[plan.plan_group][0] }}" data-plan_group="{{ plan.plan_group }}" data-id="{{ plan.plan_id }}">
                    <td>{{ plan.plan_name }}</td>
                    <td>
                        {% set run_way = plan.case_run_way %}
                        {% set run_way_01 = plan.case_run_way_01 %}
                        {% set delay_time = plan.delay_time %}
                        {% if run_way == 0 %}
                            <span>定时循环执行【间隔 {{ delay_time }} 秒】</span>
                        {% elif run_way > 0 %}
                            {% if run_way_01 == '分钟'  %}
                                <span>执行 {{ run_way }} 分钟【间隔 {{ delay_time }} 秒】</span>
                            {% else %}
                                <span>执行 {{ run_way }} 次【间隔 {{ delay_time }} 秒】</span>
                            {% endif %}
                        {% else %}
                            <span>执行一次</span>
                        {% endif %}
                    </td>
                    {% set groupid = plan.plan_group %}
                    <td>
                        {% if groupid < 1 %}
                            <span>无</span>
                        {% else %}
                            {% if tem_groups[groupid][3] == 1 %}
                                <span>{{ tem_groups[groupid][0] }}【<span style="color: green;">启用</span>】</span>
                            {% else %}
                                <span>{{ tem_groups[groupid][0] }}【<span style="color: red;">禁用</span>】</span>
                            {% endif %}
                        {% endif %}
                    </td>

                    <td>
                        <span>{{ tem_groups[groupid][1] }}/{{ tem_groups[groupid][2] }}</span>
                    </td>

                    <td>
                        {% set status = plan.status %}
                        {% if status == 1 %}
                            <span style="color: green;">正在运行</span>
                        {% elif status == 0 %}
                            <span style="color: red;">已停止</span>
                        {% else %}
                            <span>{{ status }}</span>
                        {% endif %}
                    </td>
                    <td>{{ plan.create_by }}</td>
                    <td>{{ plan.update_by }}</td>
{#                    <td>{{ plan.create_at }}</td>#}
{#                    <td>{{ plan.update_at }}</td>#}
                    <td>
                        <button class="btn btn-default btn-xs edit-caseplan-btn">编辑</button>
                        {% if plan.status == 1 %}
                            <button class="btn btn-warning btn-xs status-caseplan-btn" id="disableBtn" value="0">停止</button>
                        {% else %}
                            <button class="btn btn-primary btn-xs status-caseplan-btn" id="enableBtn" value="1">执行</button>
                        {% endif %}
                        <button class="btn btn-danger btn-xs delete-caseplan-btn" id="delete-caseplan-btn">删除</button>
                    </td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    {{ pagination.links }}

    <!-- 新增 -->
    <div class="modal fade" id="addcaseplan-dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true" onclick="location.reload();">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加/修改用例计划</h4>
                </div>
                <div class="modal-body">
                    <form action="" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color: red">*</span>计划名称：</label>
                            <div class="col-sm-9">
                                <input maxlength="50" type="text" class="form-control" name="planname" placeholder="用例计划名称，最多50个字符">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color: red">*</span>执行方式：</label>
                            <div class="col-sm-6">
                                <input type="number" class="form-control" name="case_run_way" value="1" placeholder="必须是大于等于0的整数">
                            </div>
                            <div class="col-sm-3">
                                <label><input type="radio" id="count" name="case_run_way_01" value="次" checked="checked">次</label><span>&nbsp;&nbsp;</span>
                                <label><input type="radio" id="miniute" name="case_run_way_01" value="分钟">分钟</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"></label>
                            <div class="col-sm-9">
                                <span style="color: red">执行方式说明：0-循环执行，n-执行n次(分钟)，n<=10000</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span style="color: red">*</span>间隔时间：</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="delay_time" value="300" placeholder="必须是大于等于0的整数">
                                <span style="color: red">间隔时间：两次执行的间隔等待时间，单位为秒，默认为300，最大不超过86400</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属分组：</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="group">
                                    {% for item in tem_groups %}
                                        <option value="{{ item }}">{{ tem_groups[item][0] }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="location.reload();">关闭</button>
                    <button type="button" class="btn btn-primary" id="save-caseplan-btn">保存</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}